Imports Clo = Enhancements.Core.Logging
Imports Ere = Enhancements.Basic.RegularExpressions
Imports Exe = Enhancements.Basic.Expressions
Imports Gen = System.Collections.Generic
Imports Glo = System.Globalization
Imports Iou = System.IO
Imports Ope = Enhancements.Basic.Expressions.Operators
Imports Pri = Enhancements.Basic.Primitives
Imports Ref = System.Reflection
Imports Reg = System.Text.RegularExpressions
Imports Sys = System
Imports Tex = System.Text
Imports Val = Enhancements.Basic.Expressions.Values
Imports Xsd = System.Xml.Schema
Imports W3c = System.Xml

Namespace Enhancements.Basic.Expressions.Functions.Strings
    ''' <summary>Removes the white-space characters from the start and end of a string.</summary>
    ''' <remarks>Supports the following signatures:<list type="bullet"><item>Trim(Value As String) As String</item></list></remarks>
    <Serializable(), DebuggerStepThrough()> _
    Public NotInheritable Class Trim
        Inherits [Function]

        Private Shared __Signatures() As FunctionSignature = Nothing
        Private Shared __SignatureString As FunctionSignature = Nothing

        Shared Sub New()
            Dim _signaturesList As Gen.List(Of FunctionSignature) = New Gen.List(Of FunctionSignature)()
            __SignatureString = New FunctionSignature(New FunctionSignatureParameter() {New FunctionSignatureParameter("Value", GetType(Val.String))}, New FunctionSignatureResult(GetType(Val.String)))
            _signaturesList.Add(__SignatureString)
            __Signatures = _signaturesList.ToArray()
        End Sub

        ''' <summary>Initializes a Trim instance.</summary>
        Public Sub New()
            MyBase.New("Trim", __Signatures, Nothing)
        End Sub

        ''' <summary>Solves a function call by using the supplied signature and parameters values.</summary>
        ''' <param name="_signature">Signature specified.</param>
        ''' <param name="_parametersValues">Parameters values specified. If none, an empty array is passed.</param>
        ''' <remarks>The execution of this function implementations are considered to deliver correct results only when called through the expressions subsystem. If called directly by user code, the returned results may be incorrect.</remarks>
        ''' <exception cref="Sys.Exception">Any exception can be throwed by an implementation of this function as a result of the impossibility of generating a correct end result.</exception>
        ''' <returns> </returns>
        Public Overrides Function Solve(ByVal _signature As FunctionSignature, ByVal _parametersValues() As Sys.Object) As Sys.Object
            Dim _returnValue As Sys.Object = Nothing
            If _signature.Equals(__SignatureString) Then
                _returnValue = __SolveSignatureString(_parametersValues(0))
            End If

            Return _returnValue
        End Function

        Private Function __SolveSignatureString(ByVal _value As Sys.Object) As System.String
            Dim _valueCasted As System.String = CType(_value, System.String)
            Dim _returnValue As System.String = _valueCasted.Trim()

            Return _returnValue
        End Function

    End Class
End Namespace
